package my2Cents.tools;

import net.phys2d.raw.Body;
import net.phys2d.raw.Joint;
import net.phys2d.raw.SpringJoint;
import my2Cents.properties.CheckBox;
import my2Cents.properties.Property;
import my2Cents.properties.Slider;

public class RopeTool extends AbstractConstraintMaker {
	protected boolean makeRigid = false;
	protected int extraLength = 0;
	
	public RopeTool() {
		setName("Rope");
		CheckBox rigid = new CheckBox("Rigid",false) {
			private static final long serialVersionUID = 1L;

			public void valueChanged(boolean b) {
				makeRigid = b;
			}
		};
		addProperty(rigid);
		
		Property p = new Slider("Extra Length",0,-200,200,50,true) {
			private static final long serialVersionUID = 1L;

			public void valueChanged(int value) {
				extraLength = value;
			}
		};
		this.addProperty(p);
	}
	
	protected Joint createConstraint(Body b1, Body b2) {
		float len = start.distance(end);
		Joint j = new SpringJoint(b1,b2,start,end); 
				SpringJoint x = (SpringJoint) j;
				x.setBrokenSpringConst(10000);
				x.setSpringSize(len + extraLength);
				x.setCompressedSpringConst(0);
				x.setMaxSpringSize(len + extraLength);
				if(makeRigid) {
					x.setMinSpringSize(len + extraLength);
				}
		return j;
	}
}
